﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NextCMS.Models;

public partial class ContactUsSettings : WebadminBasePage
{
    int id = 0;
    int PageModuleId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        int.TryParse(Convert.ToString(Request.QueryString["Id"]), out id);
        int.TryParse(Convert.ToString(Request.QueryString["PageModuleId"]), out PageModuleId);
        if (!IsPostBack)
        {
            GetData();
        }
        
    }
    
    void GetData()
    {
        
        if (id > 0)
        {
            PageFormsHelper pfc = new PageFormsHelper();
            PageContactUsFormModel pcm = pfc.GetById<PageContactUsFormModel>(id);
            txtEmail.Text = pcm.SendEmailTo;
            txtURL.Text = pcm.RedirectToURL;
        }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        PageFormsHelper pcc = new PageFormsHelper();
        PageContactUsFormModel pcm = pcc.GetById<PageContactUsFormModel>(id);
        if (pcm == null)
            pcm = new PageContactUsFormModel();
        
        pcm.SendEmailTo = txtEmail.Text;
        pcm.RedirectToURL = txtURL.Text;
        if (id > 0)
            pcc.Edit(pcm);
        else
            id = pcc.Save(pcm);


        PageModulesHelper pmc = new PageModulesHelper();
        PageModuleModel pmm = pmc.GetById(PageModuleId);
        pmm.RefId = id;
        pmc.Edit(pmm);
        
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "d", "window.parent.closeDialogWindow();", true);
    }

}